package com.meichis.yndms.model;

import android.os.Build;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.collection.ArrayMap;
import androidx.room.Entity;
import androidx.room.Ignore;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

@Entity(primaryKeys = {"ID", "DicTableName"})
public class DicDataItem implements Serializable {

    private int ID = 0;
    private String Name = "";
    private String Value = "";
    private String Remark = "";
    @NonNull
    private String DicTableName = "";
    private int OwnerType = 0;
    private int OwnerClient = 0;

    //商品异常状态
    @Ignore
    private InspectResult result = new InspectResult();

    //产品扩展信息
    @Ignore
    private transient ArrayMap<String, String> ExtInfo;


    public DicDataItem() {
    }


    public DicDataItem(int ID, String name) {
        this.ID = ID;
        Name = name;
    }

    public int getID() {
        return ID;
    }

    public void setID(int ID) {
        this.ID = ID;
    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name.substring(name.lastIndexOf(".") + 1);
    }

    public String getValue() {
        return Value;
    }

    public void setValue(String value) {
        Value = value;
    }

    public String getRemark() {
        return Remark;
    }

    public void setRemark(String remark) {
        Remark = remark;
    }

    public String getDicTableName() {
        return DicTableName;
    }

    public void setDicTableName(String dicTableName) {
        DicTableName = dicTableName;
    }

    public int getOwnerType() {
        return OwnerType;
    }

    public void setOwnerType(int ownerType) {
        OwnerType = ownerType;
    }

    public int getOwnerClient() {
        return OwnerClient;
    }

    public void setOwnerClient(int ownerClient) {
        OwnerClient = ownerClient;
    }


    //按照id从小到大排序
    public static void sortByID(ArrayList<DicDataItem> list) {

        Collections.sort(list, new Comparator<DicDataItem>() {
            @RequiresApi(api = Build.VERSION_CODES.N)
            @Override
            public int compare(DicDataItem o1, DicDataItem o2) {
                return o1.getID() - o2.getID();
            }
        });
    }


    public InspectResult getResult() {
        return result;
    }

    public void setResult(InspectResult result) {
        this.result = result;
    }

    public ArrayMap<String, String> getExtInfo() {
        return ExtInfo;
    }

    public void setExtInfo(ArrayMap<String, String> extInfo) {
        ExtInfo = extInfo;
    }
}
